 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Model_users extends CI_Model{
	
    
	public function allow_log_in()
        {
            $key  = array('email'=>$this->input->post('txtEmail'),'password'=>md5($this->input->post('txtPassword')));
            $user = new QUERY(array('TABLE'=>'member','KEY'=>$key,'COLS'=>'member_id'));
           
            return $user->numRows() == 1 ? $user->fetch('member_id') : false;     
	}
	
     public function add_user()
	 {
		$this->load->helper('date');
		  
		$data = array('first_name'      => $this->input->post('txtFirstName'),
		              'last_name'       => $this->input->post('txtLastName'), 
		              'photo'           => 'user_icon.jpg',
		              'email'           => $this->input->post('txtEmail'),
			      'password'        => md5($this->input->post('txtPassword')),
			      'date_registered' => date('Y-m-d H:i:s') 
		              ); 
	 		
		$user  = new QUERY(array('TABLE'=>'member'));
                $query = $user->save($data);
                
                return $query? $user->lastId():false;		  
	 }
	 
	 public function get_user_info($conditions = array(), $fields = array())
	 {
                 $key     = $conditions;
                 $columns = !empty($fields) ? $fields : array('first_name','last_name','email','photo');
                 
                 $user = new QUERY(array('TABLE'=>'member','KEY'=>$key,'COLS'=>$columns));
                 $info = $user->fetchRow();
                 
		 return $info;
	 }	 
         
         public function get_user_group($userId)
         {
             $group = new QUERY(array('TABLE'=>'group_assignment','KEY'=>array('member_id'=>$userId),'COLS'=>'group_id'));
             $group_id = $group->fetch('group_id');
             return $group_id;
         }
        
         
        
} // END OF CLASS
?>